package com.oliver.picturebackend.model.dto.picture;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.oliver.picturebackend.model.entity.Picture;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @ClassName PictureUploadRequest
 * @Description TODO
 * @Author snow
 * @Date 2024/12/13 21:25
 **/
@Data
public class PictureUploadRequest implements Serializable {

    /**
     * 图片 id（用于修改）
     */
    private Long id;

    /**
     * 文件url
     */
    private String fileUrl;

    /**
     * 图片名称
     */
    private String picName;

    /**
     * 分类
     */
    private String category;

    /**
     * 标签
     */
    private List<String> tags;

    private static final long serialVersionUID = 1L;

    public Picture cusSetInfo(Picture picture){
        if (StrUtil.isNotBlank(category)){
            picture.setCategory(category);
        }
        if (CollUtil.isNotEmpty(tags)){
            picture.setTags(JSONUtil.toJsonStr(tags));
        }
        return picture;
    }
}

